package wasweisichquiz;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;

/**
 * @version Revision 27 - MAIN Changes 
 * + Loader.java erstellt
 * @author Rafael
 * 
 */

@SuppressWarnings("serial")
public class Loader extends JFrame {

	private JPanel contentPane;
	private JLabel lblLade;
	int pbarValue = 0;

	JProgressBar progressBar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Loader frame = new Loader();
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		frame.iterate(); // fake progress

		frame.setVisible(false);
		new Quiz();

	}

	
	/**
	 * Iterate - Simulate the progress of the progress bar
	 */
	public void iterate() {
		int sleeptime;
		while (pbarValue < 101) {
			progressBar.setValue(pbarValue);
			// Instead of a fixed value=33, its pseudo random...
			sleeptime = (int)(50 * Math.random()) + 1;
			
			try {
				Thread.sleep(sleeptime);
			} catch (InterruptedException e) {
			}
			pbarValue++;
			progressBar.repaint();
		}
		if (pbarValue >= 101)
			lblLade.setText("");
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}
	}

	/**
	 * Create the frame.
	 */
	public Loader() {
		super("WWiQ wird geladen...");
		setRootPaneCheckingEnabled(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 400, 300);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(248, 248, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		progressBar = new JProgressBar();
		// progressBar.setForeground(Color.YELLOW); // Progressbar Farbe setzen
		progressBar.setEnabled(true);
		progressBar.setBounds(30, 220, 327, 21);
		contentPane.add(progressBar);

		JLabel lblNewLabel = new JLabel("WAS");
		lblNewLabel.setForeground(Color.LIGHT_GRAY);
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 55));
		lblNewLabel.setBounds(50, 21, 155, 53);
		contentPane.add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel("WEISS");
		lblNewLabel_1.setForeground(Color.GRAY);
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 40));
		lblNewLabel_1.setBounds(198, 58, 155, 39);
		contentPane.add(lblNewLabel_1);

		JLabel lblNewLabel_2 = new JLabel("ICH");
		lblNewLabel_2.setForeground(Color.DARK_GRAY);
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 30));
		lblNewLabel_2.setBounds(10, 85, 113, 53);
		contentPane.add(lblNewLabel_2);

		JLabel lblNewLabel_3 = new JLabel("QUIZ");
		lblNewLabel_3.setHorizontalTextPosition(SwingConstants.CENTER);
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 80));
		lblNewLabel_3.setBounds(77, 105, 256, 102);
		contentPane.add(lblNewLabel_3);

		lblLade = new JLabel("  Lade...");
		lblLade.setHorizontalAlignment(SwingConstants.LEFT);
		lblLade.setBounds(30, 206, 70, 14);
		contentPane.add(lblLade);
	}

}
